package com.tanhua.dubbo.api.mongo;

import com.tanhua.domain.mongo.TestOptions;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class TestOptionApiImpl implements TestOptionApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    //通过试题Id 查找对应选项
    @Override
    public List<TestOptions> findOptionByQuestionId(String questionId,Integer type) {
        Query query = new Query(Criteria.where("followQuestionId").is(questionId).and("type").is(type.toString()));
        List<TestOptions> options = mongoTemplate.find(query, TestOptions.class);
        return options;
    }

    @Override
    public TestOptions getScore(String questionId, String optionId) {
        Query query = new Query(Criteria.where("followQuestionId").is(questionId).and("_id").is(optionId));
         return mongoTemplate.findOne(query, TestOptions.class);

    }
}
